﻿using MediatR;
using W.Purchase.API.Application.Command.ClientCommand;
using W.Purchase.Domain;
using W.Purchase.Repository.Interface;

namespace W.Purchase.API.Application.CommandHandler.ClientCommandHandler
{
    public class ClientAddCommandHandler : IRequestHandler<ClientAddCommand, int>
    {
        private readonly IClientRepository repository ;
        public ClientAddCommandHandler(IClientRepository repository)
        {
            this.repository = repository;
        }
        public async Task<int> Handle(ClientAddCommand request, CancellationToken cancellationToken)
        {
            request.IsDelete = false;
            request.CreateTime = DateTime.Now;
            return await repository.AddAsync(new Client()
            {
                ClientNo=request.ClientNo,
                ClientName=request.ClientName,
                ClientFax=request.ClientFax,
                ClientPhone=request.ClientPhone,
                ClientEmail=request.ClientEmail,
                ClientRemark=request.ClientRemark,
                office_id= request.office_id,
                user_id = request.user_id
            });
        }
    }
}
